package skripsi.GeometriAndroid;


import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

public class Map{

    private int BMP_ROWS;
    private int BMP_COLUMNS;
    private Bitmap bmp;
    private Rect spriteFrame;
    private int[][] frameSequence;
    private int width;
    private int height;

    public Map(Bitmap bmp,int col,int row) {
          this.BMP_COLUMNS=col;
          this.BMP_ROWS=row;
    	  this.width = bmp.getWidth() / BMP_COLUMNS;
          this.height = bmp.getHeight() / BMP_ROWS;
          this.bmp = bmp;
          this.spriteFrame=new Rect(0,0,0,0);
          this.spriteFrame.left=0;
          this.spriteFrame.top=0;
          this.spriteFrame.right=width;
          this.spriteFrame.bottom=height;
    }

	public int getWidth(){
		return this.width;
	}
	
	public int getHeight(){
		return this.height;
	}
    
    public void setFrameSequence(int[][] frameSeq){
		this.frameSequence=frameSeq;
	}
	
	
	public void onDraw(Canvas canvas){
		for(int i=0;i<frameSequence[0].length;i++){
			for(int j=0;j<frameSequence.length;j++){
				createFrame(frameSequence[j][i]);
				Rect dest = new Rect(i*width,j*height,(i*width)+width,(j*height)+height);
		  		canvas.drawBitmap(bmp, spriteFrame, dest, null);
			}
		}
		}
	
	
	public void createFrame(int frameNumber){
		int x=frameNumber%BMP_COLUMNS;
		int y=frameNumber/BMP_COLUMNS;
		this.spriteFrame.left=x*width;
		this.spriteFrame.right=spriteFrame.left+width;
		this.spriteFrame.top=y*height;
		this.spriteFrame.bottom=spriteFrame.top+height;
	}

}

